<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          @click="downLoad"
          v-hasPermi="['system:file:load']"
          >下载选中报告</el-button>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="ossConfigList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"  align="center" />
      <el-table-column type="index" label="行号" align="center" >
        <template slot-scope="scope">
          {{scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column label="左文件名" align="center" prop="leftName"/>
      <el-table-column label="右文件名" align="center" prop="rightName" width="200"/>
      <el-table-column label="重合度" align="center" prop="prefix" />
      <el-table-column label="比对时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="clickOne(scope.row)"
            v-hasPermi="['system:oss:list']"
          >查看详情</el-button>
      </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listResult,downLoadResult} from "@/api/system/result";

export default {
  name: "Result",
  data() {
    return {
      id: "",
      checkId: "",
      pdfUrl:'',
      pdfSrc: '', // pdf文件src
      pageCount: 0, // pdf文件总页数
      currentPage: 1, // pdf文件页码
      flag: false,
      dialog: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对象存储配置表格数据
      ossConfigList: [],
      resultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否https字典
      isHttpsOptions: [],
      // 状态(0正常 1停用)字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        leftName: undefined,
        rightName: undefined,
        prefix: undefined,
        createTime: undefined,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.checkId = this.$route.query.id;
    this.getList();
  },
  methods: {
    clickOne(row) {
      if(this.ossConfigList == null){
        this.$message('比对结果为空,无重复内容');
      }else{
        this.id = row.id || this.ids;
        this.$router.push({
          path: '/system/oss-config/resultDetail',
          query: {
            //要传的参数
            id: this.id,
          },
        })
      }
    },
    // 下载
    downLoad() {
      downLoadResult().then((response) => {
        const blob = new Blob([response]); // 把得到的结果用流对象转一下
        var a = document.createElement("a"); //创建一个<a></a>标签
        a.href = URL.createObjectURL(blob); // 将流文件写入a标签的href属性值
        a.download = `${new Date().getTime()}_比对结果.docx`; //设置文件名
        a.style.display = "none"; // 障眼法藏起来a标签
        document.body.appendChild(a); // 将a标签追加到文档对象中
        a.click(); // 模拟点击了a标签，会触发a标签的href的读取，浏览器就会自动下载了
        a.remove(); // 一次性的，用完就删除a标签
      });
    },
    /** 查询对象存储配置列表 */
    getList() {
      this.loading = true;
      listResult(this.checkId).then((response) => {
        this.ossConfigList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        leftName: undefined,
        rightName: undefined,
        prefix: undefined,
        createTime: undefined,
        status: "1",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.ossConfigId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
